<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>4_运算符</title>
</head>
<body>
<script>
    console.log(6/2);//3
    console.log(3/2);//1.5
    //如果比较运算符左右两边任意一边有数字，会将字符串转换为数字再比较
    console.log(3>10);//false
    console.log(3>'10');//false
    console.log('3'>10);//false
    //如果比较运算符左右两边都是字符串，比较字符串的编码值
    console.log('3'>'10');//true
    console.log('宇'>'博');//true
    console.log('程晓宇'.charCodeAt(2));//第3个字符（数组下标代表的位置）的编码值
    console.log('博'.charCodeAt());//默认第一个字符的编码值

    console.log('***********************');
    //Number()将参数转换为数字，如果得不到数值类型的结果，会得到NaN
    console.log(Number('3'),typeof Number('3'));
    console.log(Number(true),typeof Number(true));//1
    console.log(Number(false),typeof Number(false));//0
    console.log(Number('你好'),typeof Number('你好'));//NaN(Not a Number)

    let a = 1;
    let b = true;
    //松散比较运算符，只比较值
    console.log(a == b);//true
    //严格比较运算符，先比较数据类型，再比较值
    console.log(a === b);//false

    //三元运算符
    let c = 0;
    console.log(c == 0 ? 'YES' : 'NO');//YES
    console.log(c = 0 ? 'YES' : 'NO');//NO 将 = 右侧的运算结果赋值给 c 再打印，0 代表false

    //以下5个结果都是false，除此之外全是true
    console.log(Boolean(0));
    console.log(Boolean(null));
    console.log(Boolean(undefined));
    console.log(Boolean(NaN));
    console.log(Boolean(''));

    console.log(Boolean(' '));
    console.log(Boolean('马上下课了'));
</script>
</body>
</html>